package com.mzkj.wanjulaile.mobile.api.modules.order.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mzkj.wanjulaile.mobile.api.common.entity.DataEntity;
import com.mzkj.wanjulaile.mobile.api.modules.account.entity.Account;
import com.mzkj.wanjulaile.mobile.api.modules.address.entity.Address;
import com.mzkj.wanjulaile.mobile.api.modules.coupon.entity.AccountCoupon;
import com.mzkj.wanjulaile.mobile.api.modules.order.constant.Constant;
import com.mzkj.wanjulaile.mobile.api.modules.toy.entity.Toy;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
 * 订单管理Entity
 *
 * @author ianly
 * @version 2016-10-13
 */
public class Order extends DataEntity<Order> {

    private static final long serialVersionUID = 1L;
    private String orderNumber;        // 订单编号
    private Account account;        // 下单会员
    private Address address;        // 收货地址
    private Integer orderFee;        // 订单费用
    private Integer shipFee;        //运费
    private Integer status;        // 订单状态
    private Date confirmDate;        // 确认时间
    private Date shipDate;        // 配送时间
    private Date receiveDate;   //签收时间
    private Date finishDate;        // 完成时间
    private String appointDate; //用户预约配送时间
    private String appointDate2; //预约时间不带星期
    private Integer payStatus;    //支付状态
    private Integer curVipType;    //下单时的vip类型
    private Date cancelDate;	//订单取消时间即申请退运费时间
    private String batchNo;		//退款批次号
    private String wxRefundStatus;	//微信方处理退款的状态

    private Integer couponVal; //优惠券金额
    private AccountCoupon accountCoupon;//优惠券

    private String firstFlag;	//首单标志 0(默认)普通单 1第一单
    private String lastFlag;	//是否最后一单 0(默认)否 1 是

    private List<OrderToy> orderToys;
    /**
     * 数据显示使用
     */
    private String statusName; //订单状态名称

    /**
     * 查询条件
     */
    private String startDate;
    private String endDate;

    public Order() {
        super();
    }

    public Order(String id) {
        super(id);
    }

    public String getOrderNumber() {
        return orderNumber;
    }

    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;
    }

    public Account getAccount() {
        return account;
    }

    public void setAccount(Account account) {
        this.account = account;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    @NotNull(message = "订单费用不能为空")
    public Integer getOrderFee() {
        return orderFee;
    }

    public void setOrderFee(Integer orderFee) {
        this.orderFee = orderFee;
    }

    @NotNull(message = "订单状态不能为空")
    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date getConfirmDate() {
        return confirmDate;
    }

    public void setConfirmDate(Date confirmDate) {
        this.confirmDate = confirmDate;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date getShipDate() {
        return shipDate;
    }

    public void setShipDate(Date shipDate) {
        this.shipDate = shipDate;
    }

    public Date getReceiveDate() {
        return receiveDate;
    }

    public void setReceiveDate(Date receiveDate) {
        this.receiveDate = receiveDate;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date getFinishDate() {
        return finishDate;
    }

    public void setFinishDate(Date finishDate) {
        this.finishDate = finishDate;
    }

    public List<OrderToy> getOrderToys() {
        return orderToys;
    }

    public void setOrderToys(List<OrderToy> orderToys) {
        this.orderToys = orderToys;
    }

    public String getStartDate() {
        return startDate;
    }

    public void setStartDate(String startDate) {
        this.startDate = startDate;
    }

    public String getEndDate() {
        return endDate;
    }

    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }

    public String getAppointDate() {
        return appointDate;
    }

    public void setAppointDate(String appointDate) {
        this.appointDate = appointDate;
    }

    public Integer getShipFee() {
        return shipFee;
    }

    public void setShipFee(Integer shipFee) {
        this.shipFee = shipFee;
    }

    public Integer getPayStatus() {
        return payStatus;
    }

    public void setPayStatus(Integer payStatus) {
        this.payStatus = payStatus;
    }

    public Integer getCurVipType() {
        return curVipType;
    }

    public void setCurVipType(Integer curVipType) {
        this.curVipType = curVipType;
    }

    public String getAppointDate2() {
        appointDate2 = appointDate;
        if (appointDate != null && appointDate.indexOf("(") > 0) {
            appointDate2 = appointDate.substring(0, appointDate.indexOf("("));
        }
        return appointDate2;
    }

    public Integer getCouponVal() {
        return couponVal;
    }

    public void setCouponVal(Integer couponVal) {
        this.couponVal = couponVal;
    }

    public AccountCoupon getAccountCoupon() {
        return accountCoupon;
    }

    public void setAccountCoupon(AccountCoupon accountCoupon) {
        this.accountCoupon = accountCoupon;
    }

    public Date getCancelDate() {
        return cancelDate;
    }

    public void setCancelDate(Date cancelDate) {
        this.cancelDate = cancelDate;
    }

    public String getBatchNo() {
        return batchNo;
    }

    public void setBatchNo(String batchNo) {
        this.batchNo = batchNo;
    }

    public String getWxRefundStatus() {
        return wxRefundStatus;
    }

    public void setWxRefundStatus(String wxRefundStatus) {
        this.wxRefundStatus = wxRefundStatus;
    }

    public String getStatusName() {
        if (Constant.ORDER_CREATE.equals(status)) {
            statusName = "订单提交";
        } else if (Constant.ORDER_CONFIRM.equals(status)) {
            statusName = "订单确认";
        } else if (Constant.ORDER_SENDING.equals(status)) {
            statusName = "配送中";
        } else if (Constant.ORDER_RECEIVED.equals(status)) {
            statusName = "已签收";
        } else if (Constant.ORDER_COMPLETE.equals(status)) {
            statusName = "订单完成";
        } else if (Constant.ORDER_CANCEL.equals(status)) {
            statusName = "订单取消";
        } else  {
            statusName = "未知";
        }
        return statusName;
    }

    public String getFirstFlag() {
        return firstFlag;
    }

    public void setFirstFlag(String firstFlag) {
        this.firstFlag = firstFlag;
    }

    public String getLastFlag() {
        return lastFlag;
    }

    public void setLastFlag(String lastFlag) {
        this.lastFlag = lastFlag;
    }
}